package com.zilue.payment.gateway.paramter.order;

import com.zilue.payment.gateway.annotation.ParameterFiledCheck;
import com.zilue.payment.gateway.paramter.BaseParameter;
import com.zilue.payment.gateway.paramter.ParameterCheckResult;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by zilue on 2017/3/8.
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RefundParameter extends BaseParameter {
    @ParameterFiledCheck(regex = "\\w{0,32}", description = "商户订单号,1-32个字符,字母/数字/_")
    private String order_no;
    @ParameterFiledCheck(regex = "\\w{0,32}", description = "支付系统单号,1-32个字符,字母/数字/_")
    private String out_trade_no;
    @ParameterFiledCheck(regex = "\\w{0,32}", description = "第三方订单号,1-32个字符,字母/数字/_")
    private String out_pay_no;
    @ParameterFiledCheck(regex = "\\w{0,32}", description = "退费批次号,1-32个字符,字母/数字/_")
    private String out_refund_no;
    @ParameterFiledCheck(regex = "\\d{0,11}", description = "退费金额（单位为分）,1-11位数字")
    private Long fee;
    @ParameterFiledCheck(regex = "[\\s\\S]{0,256}", description = "退款原因,1-256个字符,字母/数字/_")
    private String reason;
    private String terminal_id;
    private String operator_id;
    private String store_id;

    @Override
    public ParameterCheckResult complicated() {
        if (StringUtils.isEmpty(order_no) && StringUtils.isEmpty(out_trade_no) && StringUtils.isEmpty(out_pay_no)) {
            return ParameterCheckResult.createErrorResult("order_no , out_trade_no , out_pay_no","三个参数中必须传一个参数");
        }
        if (StringUtils.isEmpty(out_refund_no)&&fee!=null){
            return ParameterCheckResult.createErrorResult("out_refund_no","如果您传了fee ，必须传out_refund_no");
        }
        return ParameterCheckResult.createSuccess();
    }
}
